<template>
  <el-dialog :visible.sync="closeOrderListOpenFlag" center :append-to-body="true" :lock-scroll="false" width="75%"
    z-index="2007">
    <div style="width: 100%;">
      <div style="width: 100%;">
        <h3 style="text-align: center;">接单关闭列表</h3>
        <el-table ref="multipleTable" :data="tableData" border style="width: 100%" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55 ">
          </el-table-column>
          <el-table-column prop="goodsName" label="蛋糕名称">
          </el-table-column>
          <el-table-column prop="specs" label="规格">
          </el-table-column>
          <el-table-column prop="regionName" label="地区">
          </el-table-column>
          <el-table-column prop="warehouseName" label="仓库">
          </el-table-column>
        </el-table>
        <pagination v-show="tableDatatotal>0" :total="tableDatatotal" :page.sync="getCloseOrderListParams.page"
          :limit.sync="getCloseOrderListParams.size" @pagination="getCloseOrderList" />
        <div style="text-align: center;margin-top: 20px;">
          <el-button type="primary" @click="toggleSelectionOpen()">开启接单</el-button>
          <el-button @click="closeOrderListOpenFlag = false" plain>取消</el-button>
        </div>
      </div>
    </div>
  </el-dialog>
</template>

<script>
import {
  getCloseOrderList, // 接单关闭订单列表
  getUpCloseOrder, // 开启接单
} from '@/api/shop';
import Pagination from "@/components/Pagination"; // secondary package based on el-pagination
export default {
  data() {
    return {
      tableData: [], // 关闭接单列表数据
      closeOrderListOpenFlag: false,
      getUpCloseOrderQuery: { // 开启接单列表
        goodsCloseIds: []
      },
      tableDatatotal: 0,
      getCloseOrderListParams: {
        cityId: JSON.parse(window.localStorage.getItem("saber-areaId")).content,
        warehouseId: '',
        page: 1,
        size: 10,
        limit: 10
      },
    };
  },
  methods: {
    show() {
      this.closeOrderListOpenFlag = true
      this.getCloseOrderList()
    },
    getCloseOrderList() {
      getCloseOrderList({}).then(res => {
        if (res.data.code == 200) {
          this.tableDatatotal = res.data.data.total
          this.tableData = res.data.data.rows
        }
      })
    },
    // 关闭接单列表
    handleSelectionChange(val) {
      this.getUpCloseOrderQuery.goodsCloseIds = [];
      // this.multipleSelection = val;
      val.forEach(item => {
        this.getUpCloseOrderQuery.goodsCloseIds.push(item.id)
      })
    },
    // 开启接单
    toggleSelectionOpen() {
      if (this.getUpCloseOrderQuery.goodsCloseIds !== '') {
        getUpCloseOrder(this.getUpCloseOrderQuery).then(res => {
          if (res.data.code == 200) {
            this.$notify({
              title: '操作成功',
              message: '请您耐心等待',
              type: 'success'
            })
            this.closeOrderListOpenFlag = false;
            this.getCloseOrderListParams.page = 1;
          }
        })
      }
    },
  },
  components: {
    Pagination
  }
};
</script>
<style lang="scss" scoped>

</style>